package com.shujia.springboot.service;

import com.shujia.springboot.dao.StuSumScoreDao;
import com.shujia.springboot.entity.StuSumScore;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StuSumScoreService {
    @Resource
    StuSumScoreDao stuSumScoreDao;

    // 返回所有的学生总分数据
    public List<StuSumScore> findAllStuSumScore() {
        return stuSumScoreDao.findAll();
    }

    // 根据班级返回所有学生总分数据
    public Page<StuSumScore> getStuSumScoreByPageWithClazzOption(int pageSize,int pageNum,String clazz){
        PageRequest page = PageRequest.of(pageNum - 1, pageSize);
        return stuSumScoreDao.findByClazzOption(clazz,page);
    }

    // 根据pageSize、pageNum做分页
    public Page<StuSumScore> getStuSumScoreByPage(int pageSize, int pageNum) {
        PageRequest page = PageRequest.of(pageNum - 1, pageSize);
        return stuSumScoreDao.findAll(page);
    }

    // 根据id删除数据
    public void deleteById(int id) {
        stuSumScoreDao.deleteById(id);
    }

    // 增加一个学生
    public void addOrEditStuSumScore(StuSumScore stuSumScore) {
        stuSumScoreDao.save(stuSumScore);
    }


}
